<template>
	<view class="hbh_container2">
		<headComponent navTitle="忘记密码" :isBack="true"></headComponent>
		<view class="hbh_box">
			<view class="navBar">
				<view class="active">
					忘记密码
				</view>
			</view>
			<!-- 			<SendCode :maxlength="11" :inpType="'number'" :placeholder="'请输入您的手机号'" @sendValue="sendCode3">
			</SendCode> -->
			<SendCode :maxlength="6" :inpType="'number'" :placeholder="'请输入验证码'" @sendValue="sendCode4"
				@putCode="putCode" :isCode="true"></SendCode>
			<SendCode :password="true" :isSee="true" :placeholder="'设置新的密码'" @sendValue="sendCode">
			</SendCode>
			<SendCode :password="true" :isSee="true" :placeholder="'请再次确认密码'" @sendValue="sendCode2">
			</SendCode>
			<view class="hbh_endBtn" @click="subBtn">
				提交
			</view>
			<Createcode :titleName="'注册验证码为'" :code="localCode" v-if="isShowCode"></Createcode>
		</view>

	</view>
</template>

<script>
	import {
		findBackPwd
	} from "@/api/index.js"
	import Createcode from "@/components/Createcode/Createcode.vue"
	import SendCode from "@/components/hbhInput/hbhInput.vue"
	export default {
		data() {
			return {
				newLoginPwd: "",
				loginPwd: "",
				isFill: false,
				localCode: "",
				isShowCode: false,
				code: ""
			};
		},
		components: {
			SendCode,
			Createcode
		},
		methods: {
			subBtn() {
				if (!this.newLoginPwd || !this.loginPwd || !this.localCode) {
					uni.showToast({
						icon: "error",
						title: "表单不全"
					})
					return
				}
				if (this.code == this.localCode) {
					if (this.newLoginPwd == this.loginPwd) {
						plus.device.getInfo({ //需要勾选IDFA
							success: (e) => {
								findBackPwd({
									uuid: e.uuid
								}).then((res) => {
									console.log(res)
									// setTimeout(() => {
									// 	uni.reLaunch({
									// 		url: "/pages/login/login"
									// 	});
									// }, 1500)
									// uni.showToast({
									// 	icon: "success",
									// 	title: res.msg,
									// 	duration: 1000
									// })

								}).catch((err) => {
									console.log(err)
									if (err.code && err.code == 400) {
										uni.showToast({
											icon: "none",
											title: err.msg
										})
									} else {
										uni.showToast({
											icon: "none",
											title: "表单填写异常!"
										})
									}

								})
							},
							fail: function(e) {
								console.log('getDeviceInfo failed: ' + JSON.stringify(e));
							}
						});
					} else {
						uni.showToast({
							icon: "none",
							title: "两次输入密码不一致！"
						})
					}
				} else {
					uni.showToast({
						icon: "none",
						title: "验证码错误!"
					})
				}
			},
			sendCode(val) {
				this.newLoginPwd = val
			},
			sendCode2(val) {
				this.loginPwd = val
			},
			sendCode4(val) {
				this.code = val
			},
			//接收验证码
			putCode(val) {
				this.localCode = val
				this.isShowCode = true
				this.timer = setTimeout(() => {
					this.isShowCode = false
					clearTimeout(this.timer)
					this.timer = null
				}, 10000)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.navBar {
		margin-top: 122rpx;
		display: flex;
		margin-bottom: 114rpx;

		.active {
			text-align: center;
			display: flex;
			align-items: flex-end;
			font-size: 50rpx;
			font-weight: 500;
			color: #000000;
		}
	}

	.hbh_help {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 24rpx;
		font-weight: 400;
		color: #51C3FF;
	}

	.hbh_code {
		display: flex;
		justify-content: flex-end;
		align-items: center;
		font-size: 24rpx;
		font-weight: 400;
		color: #51C3FF;
	}

	.hbh_endBtn {
		width: 630rpx;
		margin-left: calc(50% - 315rpx);
		height: 90rpx;
		background: linear-gradient(90deg, #6ECDFF 0%, #00A7FF 100%);
		border-radius: 50rpx 50rpx 50rpx 50rpx;
		opacity: 1;
		font-size: 36rpx;
		font-weight: 500;
		color: #FFFFFF;
		text-align: center;
		line-height: 90rpx;
		margin-top: 100rpx;
	}
</style>